#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QUdpSocket>
#include "ui_mainwindow.h"

class Gameboard;
class Dialog;
struct Coord;

namespace Ui {
  class MainWindow;
}

class MainWindow : public QMainWindow
{
  Q_OBJECT
  friend class Dialog;

public:
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();

public slots:
  void receiveData();
  void selected();
  void sendMessage();

private:
  Ui::MainWindow *ui;
  Gameboard *board;
  QUdpSocket *udp;
  QHostAddress *opponentAddress;
  Dialog *prompt;
  QPushButton *uiBoard[8][8];
  QPushButton *squareSelected;
  Coord *previousSelected;
  int player;   // is the player WHITE or BLACK?
  int turn; // is it WHITE or BLACK player's turn

  void displayBoard();
  void updatePiece(int oldx, int oldy, int newx, int newy);
  void castle(int rookX, int kingX, int newRookX, int newKingX);
  void removePiece(int x, int y);
  bool validMove(int oldx, int oldy, int newx, int newy); // defined in validmove.h
  void sendMove(int oldx, int oldy, int newx, int newy);
  void decideColors();
  void sendCastle(int rookX, int kingX, int newRookX, int newKingX);
  void mainGame(QString address);
  void setupGameBoard();
  void connectPieces();
};

#endif // MAINWINDOW_H
